<?php
if (!isset($load_data)) $load_data = array();
if (!isset($enable_delete)) $enable_delete = true;
if (!isset($enable_edit)) $enable_edit = true;
?>
<h3 class="xrvel_scaffolding_header">View <?php echo $xs_friendly_name; ?> Data</h3>
<div><a href="index.php/<?php echo $this->uri->segment(1); ?>/add/">Add Data</a></div>
<?php $this->load->view('xrvel_scaffolding/ok-error'); ?>
<?php if ($load_data == array()) : ?>
	<div class="xrvel_scaffolding_no_data">
		You have no data
	</div>
<?php else : ?>
	<table border="1" cellpadding="5" cellspacing="0" style="width:100%" class="xrvel_scaffolding_table_view">
		<tr valign="top">
			<?php foreach ($xs_view_columns as $data) : ?>
				<th><?php echo $data; ?></th>
			<?php endforeach; ?>
			<?php if ($enable_delete && $enable_edit) : ?>
			<th>&nbsp;
				
			</th>
			<?php endif; ?>
		</tr>
	<?php foreach ($load_data as $data) : ?>
		<tr valign="top">
			<?php foreach ($data as $xs_name=>$xs_value) :
				$styles = array();
				if (isset($xs_column_info[$xs_name])) {
					if ($xs_column_info[$xs_name]['type'] == 'int' && (!isset($xs_column_info[$xs_name]['dont_treat_as_int']) || $xs_column_info[$xs_name]['dont_treat_as_int'] === false)) {
						$styles[] = 'text-align:right';
					}
					if (isset($xs_column_info[$xs_name]['on_view'])) {/* call user defined function ? */
						$xs_value = call_user_func($xs_column_info[$xs_name]['on_view'], $xs_value);
					}
				}
				if ($styles != array()) {
					$styles = implode(';', $styles);
				} else {
					$styles = '';
				}
				?>
			<td <?php if ($styles != '') { echo 'style="'.$styles.'"'; }; ?>>
				<?php echo $xs_value; ?>
			</td>
			<?php endforeach; ?>
			<?php if ($enable_delete && $enable_edit) : ?>
			<td>
				<?php if ($enable_edit) : ?>
				<a href="index.php/<?php echo $this->uri->segment(1); ?>/edit/<?php echo $data[$xs_primary_key]; ?>/">Edit</a>
				<?php endif; ?>
				&nbsp;
				<?php if ($enable_delete) : ?>
				<a href="index.php/<?php echo $this->uri->segment(1); ?>/delete/<?php echo $data[$xs_primary_key]; ?>/">Delete</a>
				<?php endif; ?>
			</td>
			<?php endif; ?>
		</tr>
	<?php endforeach; ?>
	</table>
<?php endif; ?>
